// 店铺管理
import { defineStore } from 'pinia'
import { reactive } from 'vue'
import {
	requestGetShopbyId,
	requestShopAdd,
	requestShopChainDisable,
	requestShopChainEnable,
	requestShopDel,
	requestShopGetAll,
	requestShopGetStoreByCity,
	requestShopInterest,
	requestShopInterestList,
	requestShopLocation,
	requestShopSelectList,
	requestShopUpdatebyId,
	Location,
	ShopInfo,
	ShopGetAll,
	Interest,
	InterestList,
	SelectList,
	StoreByCity
} from '../service/shop'

export default defineStore('useShopStore', () => {
	const shopInfoData = reactive({
		shopInfos: {},
		shopList: []
	})
	
	// 新增店鋪
	const shopAdd = async (shopInfo: Partial<ShopInfo>) => {
		const data = await requestShopAdd(shopInfo)
		console.log(data, "| 新增店鋪");
	}
	// 删除门店
	const shopDel = async (id: number) => {
		const data = await requestShopDel(id)
		console.log(data, "| 删除门店");
	}
	// 修改门店状态-禁用
	const shopDisable = async (id: number) => {
		const data = await requestShopChainDisable(id)
		console.log(data);
	}
	// 修改门店状态-启用
	const shopEnable = async (id: number) => {
		const data = await requestShopChainEnable(id)
		console.log(data);
	}
	// 获取门店列表
	const shopGetAll = async (shopGetAll: Partial<ShopGetAll>) => {
		const res = await requestShopGetAll(shopGetAll)
		shopInfoData.shopList = res?.data?.objects
	}
	// 修改门店信息
	const shopUpdatebyId = async (shopInfo : Partial<ShopInfo>) => {
		const data = await requestShopUpdatebyId(shopInfo)
		console.log(data, "| 修改门店信息");
	}
	// 获取门店信息
	const shopInfo = async (id : number) => {
		const data = await requestGetShopbyId(id)
		console.log(data, "| 获取门店信息");
		shopInfoData.shopInfos = data?.data
	}
	// 店铺关注
	const shopInterest = async (interest: Partial<Interest>) => {
		const data = await requestShopInterest(shopInfo)
		console.log(data, "| 店铺关注");
	}
	// 店铺关注列表
	const shopInterestList = async (interestList: Partial<InterestList>) => {
		const data = await requestShopInterestList(shopInfo)
		console.log(data, "| 修改门店信息");
	}
	// 用户定位上报
	const shopLocation = async (location : Location) => {
		// await requestShopLocation(location)
		await requestShopLocation({
			...location
		})
	}
	// 获取活动选中的店铺和店铺对应的城市
	const shopSelectList = async (selectList: Partial<SelectList>) => {
		const res = await requestShopSelectList(selectList)
		console.log(res, "| res");
	}
	// 获取城市下的店铺列表
	const shopGetStoreByCity = async (storeByCity: Partial<StoreByCity>) => {
		const res = await requestShopGetStoreByCity(storeByCity)
		console.log(res, "| res");
	}
	
	return {
		shopInfo,
		shopInfoData,
		shopLocation,
		shopGetAll
	}
})